<template>
	<view class="attendance-details">
		<person-infrom :propName="basicInfor.propName" :propNum="basicInfor.propNum" :propDepartment="basicInfor.propDepartment" class="header-inform"></person-infrom>
		<stastistical-chat class="chart" :charData='charData'></stastistical-chat>
		<my-calendar class="calender" :tipsData='charData' :caledarDataProps='caledarDataProps' :nowWeek="nowWeeks" :date='date'></my-calendar>
	</view>
</template>

<script>
	import apiData from '../../common/utils/apiData.js'
	import utils from '../../common/utils/utils.js'
	export default {
		data() {
			return {
				basicInfor:{},
				caledarDataProps:[],
				date:'',
				nowWeeks:'',
				charData:[]
			}
		},
		onLoad(options) {
			let user =JSON.parse(options.item)
			
			let newMonthNum = parseInt(options.month)-1
			let month  = new Date().setMonth(newMonthNum,1)
			let timeCode= new Date(month)
			this.date = options.year
			this.nowWeeks = timeCode.getDay()
			//获得当前考勤的时间
			
			
			this.basicInfor = {
				"propName":user.pk_psndoc.name,
				"propNum":user.pk_psndoc.code,
				"propDepartment":user.attdept.name
			}//获取信息
			let teamproperty = options.teamproperty//获取班组类型，3 是全日（itemm） 1 是上下午(itemm,itema) 2 是夜(itema)
			let mdayArray =[]
			let adayArray=[]
			let newCalender=[]
			if(teamproperty=='3'){
				for(let key in user){
					if(key.indexOf('pk_itemm')!='-1'){
						user[key].days = key.split('pk_itemm')[1]
						mdayArray.push(user[key])
					}	
				}
			}else if(teamproperty=='2'){
				for(let key in user){
					if(key.indexOf('pk_itema')!='-1'){
						user[key].days = key.split('pk_itema')[1]
						adayArray.push(user[key])
					}
				}
			}else if(teamproperty=='1'){
				for(let key in user){
					if(key.indexOf('pk_itema')!='-1'){
						user[key].days = key.split('pk_itema')[1]
						adayArray.push(user[key])
					}else if(key.indexOf('pk_itemm')!='-1'){
						user[key].days = key.split('pk_itemm')[1]
						mdayArray.push(user[key])
					}
				}
			}
			function sortData(a, b) {
				return a.days - b.days
			}
			if(teamproperty=='1'){
				mdayArray.sort(sortData)
				adayArray.sort(sortData)
				// let newempty = []
				// for(let i = 0; i<mdayArray.length;i++){
				// 	for(let j = 0; j<adayArray.length;j++){
				// 		if(mdayArray[i].name!=adayArray[j].name&&mdayArray[i].days==adayArray[j].days){
				// 			mdayArray[i].name='半日'+mdayArray[i].name
				// 			adayArray[j].name='半日'+adayArray[j].name
				// 		}
				// 	}
				// }//把白板和夜班有半天请假的部分理出来
				
				this.caledarDataProps = mdayArray
			}else if(teamproperty=='2'){
				adayArray.sort(sortData)
				this.caledarDataProps = adayArray
			}else if(teamproperty=='3'){
				mdayArray.sort(sortData)
				this.caledarDataProps = mdayArray
			}
			//根据类型组成对应的对象
			// else if(teamproperty=='1'){
			// 	if(key.indexOf('pk_itema')!='-1'){
			// 		adayArray[""+key+""] = user[key]
			// 	}
			// }
			// for(let key in user) {
			// 	if(key.indexOf('pk_itema')!='-1'){
			// 		adayArray[""+key+""] = user[key]
			// 	}else if(key.indexOf('pk_itemm')!='-1'){
			// 		mdayArray[""+key+""] = user[key]
			// 	}
			// }//循环遍历取出白班和夜班的对象
			let isObjNull
			
			let item
			let splStr 
			// if(teamproperty=='2'){
			// 	item=adayArray
			// 	splStr='itema'
			// 	for(let key in item){
			// 		newCalender.push({
			// 			days:key.split(splStr)[1],
			// 			value:item[key]
			// 		})
			// 	}//构建新的对象
			// }else if(teamproperty=='3'){
			// 	item=mdayArray
			// 	splStr='itemm'
			// 	for(let key in item){
			// 		newCalender.push({
			// 			days:key.split(splStr)[1],
			// 			value:item[key]
			// 		})
			// 	}//构建新的对象
			// }else if(teamproperty=='1'){
			// 	let commonValue=[]
				
			// 	item=mdayArray
			// 	splStr='itemm'
			// 	for(let key in item){
			// 		newCalender.push({
			// 			days:key.split(splStr)[1],
			// 			value:item[key]
			// 		})
			// 	}//构建新的对象
			// }
			
			
			//排序
			// this.caledarDataProps = newCalender
			// console.log(newCalender)
			
			// 图标部分,暂时只有年休假,半天年假属性
			let workChatNum = 0
			let yearLeave = 0
			
			let nameArr = user.count
			let newChart=[]
			for(let key in nameArr){
				newChart.push({
					title:key,
					days:nameArr[key]
				})
			}
			newChart.forEach(item=>{
				item.color=utils.getColorByType(item.title)
			})
			// let objDataChat = [
			// 	{days:workChatNum,title:'出勤',color:'#55aaff'},
			// 	{days:yearLeave,title:'年休假',color:'#FF2B82'},
				
			// 	{days:1,title:'出勤',color:'#37ffb3'},
			// 	{days:2,title:'事假',color:'#FF5441'}
			// ]
			this.charData = newChart
		}
		
	}
</script>

<style scoped lang="scss">
	.header-inform{
		margin: 30rpx;
	}
	.chart{
		margin-bottom: 40rpx;
	}
	.calender{
		margin: 0 auto; 
		margin-top: 40rpx;
	}
</style>
